package Drawers;

import org.eclipse.swt.graphics.*;
import Utils.*;

public class FileDrawer implements Drawer
{
	private ImageData _imageData;
	private String _fileName;
	private int _fileType;
	private boolean _stoped;
	
	public FileDrawer(String fileName, int type)
	{
		_fileName = fileName;
		_fileType = type;
		_stoped = false;
	}
	
	public void Stop()
	{
		_stoped = true;
	}
	
	public boolean ToStop()
	{
		return _stoped;
	}
	
	public void Start(Point size, PaletteData palette)
	{
		_imageData = new ImageData(size.x, size.y, 24, Functions.ClearPalette());
	}
	
	public void PutPixel(int x, int y, int color)
	{
		_imageData.setPixel(x, y, color);
	}
	
	public void Finish()
	{
		ImageLoader loader = new ImageLoader();
		loader.data = new ImageData[] {_imageData};
		loader.save(_fileName, _fileType);
	}
	
	public void PutPixel(int iter, byte r, byte g, byte b)
	{
		_imageData.data[iter] = r;
		_imageData.data[iter + 1] = g;
		_imageData.data[iter + 2] = b;
	}
	
	public int BytesPerLine()
	{
		return _imageData.bytesPerLine;
	}
	
}
